package com.bestcem.xm.user.dao.impl;

import com.bestcem.xm.user.dao.UserGroupImportRecordDao;
import com.bestcem.xm.user.dao.mapper.UserGroupImportRecordMapper;
import com.bestcem.xm.user.entity.base.Paginator;
import com.bestcem.xm.user.entity.mysql.UserGroupImportRecord;
import com.bestcem.xm.user.entity.pojo.UserGroupImportRecordDO;
import com.bestcem.xm.user.util.business.DataBaseUtil;
import com.bestcem.xm.user.util.convert.UserGroupImportRecordConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * 层级组织导入 dao实现
 *
 * @author wangyunyun <yunyun.wang@idiaoyan.com>
 * @version v1.0
 * @date 2022/4/19 17:50
 */
@Repository
public class UserGroupImportRecordDaoImpl implements UserGroupImportRecordDao {

    @Resource
    private UserGroupImportRecordConvert userGroupImportRecordConvert;

    @Resource
    private UserGroupImportRecordMapper userGroupImportRecordMapper;

    @Override
    public List<UserGroupImportRecordDO> selectBySelective(UserGroupImportRecordDO userGroupImportRecordDO) {
        return userGroupImportRecordConvert.mysqls2Dos(userGroupImportRecordMapper
                .selectBySelective(userGroupImportRecordConvert.do2Mysql(userGroupImportRecordDO)));
    }

    @Override
    public Long countBySelective(UserGroupImportRecordDO userGroupImportRecordDO) {
        return userGroupImportRecordMapper.countBySelective(userGroupImportRecordConvert.do2Mysql(userGroupImportRecordDO));
    }

    @Override
    public String insertBySelective(UserGroupImportRecordDO userGroupImportRecordDO) {
        UserGroupImportRecord userGroupImportRecord = userGroupImportRecordConvert.do2Mysql(userGroupImportRecordDO);
        userGroupImportRecord.setImportId(DataBaseUtil.generateId());
        DataBaseUtil.setCreateAndUpdateTime(userGroupImportRecord);
        userGroupImportRecordMapper.insertSelective(userGroupImportRecord);
        return userGroupImportRecord.getImportId();
    }

    @Override
    public Integer updateByIdAndOrgId(UserGroupImportRecordDO userGroupImportRecordDO) {
        UserGroupImportRecord userGroupImportRecord = userGroupImportRecordConvert.do2Mysql(userGroupImportRecordDO);
        DataBaseUtil.setUpdateTime(userGroupImportRecord);
        return userGroupImportRecordMapper.updateByPrimaryKeySelective(userGroupImportRecord);
    }

    @Override
    public List<UserGroupImportRecordDO> selectByPage(UserGroupImportRecordDO exportRecordDO, Integer currentPage, Integer pageSize) {
        // 设置分页参数并查询
        return userGroupImportRecordConvert.mysqls2Dos(userGroupImportRecordMapper
                .selectByPage(userGroupImportRecordConvert.do2Mysql(exportRecordDO), new Paginator(currentPage, pageSize)));
    }

}
